<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>else</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="control-structures.if.html">if</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="control-structures.elseif.html">elseif/else if</a></div>
 <div class="up"><a href="language.control-structures.html">流程控制</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="control-structures.else" class="sect1">
 <h2 class="title"><em>else</em></h2>
 <p class="verinfo">(PHP 4, PHP 5)</p>
 <p class="para">
  经常需要在满足某个条件时执行一条语句，而在不满足该条件时执行其它语句，这正是
  <em>else</em> 的功能。<em>else</em> 延伸了
  <em>if</em> 语句，可以在 <em>if</em>
  语句中的表达式的值为 <strong><code>FALSE</code></strong> 时执行语句。例如以下代码在
  <var class="varname"><var class="varname">$a</var></var> 大于 <var class="varname"><var class="varname">$b</var></var> 时显示
  <span class="computeroutput">a is bigger than b</span>，反之则显示
  <span class="computeroutput">a is NOT bigger than b</span>：
  <div class="informalexample">
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">$b</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"a&nbsp;is&nbsp;greater&nbsp;than&nbsp;b"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"a&nbsp;is&nbsp;NOT&nbsp;greater&nbsp;than&nbsp;b"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <em>else</em> 语句仅在 <em>if</em> 以及
  <em>elseif</em>（如果有的话）语句中的表达式的值为
  <strong><code>FALSE</code></strong> 时执行（参见 <a href="control-structures.elseif.html" class="link">elseif</a>）。
 </p>
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="control-structures.if.html">if</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="control-structures.elseif.html">elseif/else if</a></div>
 <div class="up"><a href="language.control-structures.html">流程控制</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
